<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%String path = request.getContextPath();%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <div tabid="tabA" lselected="true">
                <div class="searchArea">
                    <!-- 搜索表单开始 -->
                    <form id="searchBar">
                        <div class="fieldset1 clearFix">
                            <div class="FXBR">
                                <div class="fieldBox">
                                    <div class="label">客户名称</div>
                                    <div class="field">
                                        <input type="text" id="cstNm" name="cstNm" class="ui-textbox"
                                               ligerui="width: 160" value="">
                                    </div>
                                </div>
                                <div class="fieldBox">
                                    <div class="label">合同号</div>
                                    <div class="field">
                                        <input type="text" id="cntNo" name="cntNo" class="ui-textbox"
                                               ligerui="width: 160" value="">
                                    </div>
                                </div>
                                <div class="fieldBox">
                                    <div class="label">支付表号</div>
                                    <div class="field">
                                        <input type="text" id="paySchNo" name="paySchNo" class="ui-textbox"
                                               ligerui="width: 160" value="">
                                    </div>
                                </div>
                            </div>
                            <div class="clearFix"></div>

                            <!-- 表单按钮 -->
                            <div class="btnsBox formBtns notRight">
                                <span id="searchBtn" class="sq-button-round">查询</span>
                                <span id="clearBtn" class="sq-button-round">清空</span>
                                <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                <sys:funcAuth resCd="ASS_VF_UPLOAD">
                                    <input id="upfile" name="upfile" style="width:150px" type="file">
                                    <span onclick="uploadAndVf()" class="sq-button-round">读取文件后资产核销</span>
                                    <span>
                                        <a style="color:blue;text-decoration:underline;"
                                           href="<%=path%>/resource/template/ass/assVfDemo.xls"/>模板样例下载</a>
                                    </span>
                                </sys:funcAuth>
                            </div>
                        </div>
                    </form>
                    <!-- 搜索表单结束 -->
                </div>
                <!-- 列表显示块 -->
                <div id="ligergrid1" class="sq-grid"></div>
            </div>

        </div>
    </div>
</div>
<script type="text/javascript">
    var grid = null;
    //记录第一次勾选移交分类状态
    var trType;


    $(function () {
        $("#searchBar").ligerForm();//初始化表单
        initGrid();//初始化列表
        searchBtnEvent();//查询按钮事件
        clearBtnEvent();//清空按钮事件

    });

    //查询参数
    function getSearchParams() {
        var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
    }

    //初始化列表
    function initGrid() {
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/ass/assvfinfo/initList.do',
            method: 'get',
            parms: getSearchParams(),
            columns: [
                {
                    display: '客户姓名', name: 'cstNm', minWidth: 100,
                    render: function (rowdata, rowindex, value) {
                        return "<span title=" + rowdata.cstNm + ">" + rowdata.cstNm + "</span>";
                    }
                },
                {
                    display: '证件号码', name: 'idtyNum', minWidth: 150
                },
                {
                    display: '合同号', name: 'cntNo', minWidth: 150,
                    render: function (rowdata, rowindex, value) {
                        return "<span title=" + rowdata.cntNo + ">" + rowdata.cntNo + "</span>";
                    }
                },
                {
                    display: '支付表号', name: 'paySchNo', minWidth: 160,
                    render: function (rowdata, rowindex, value) {
                        return "<span title=" + rowdata.paySchNo + ">" + rowdata.paySchNo + "</span>";
                    }
                },
                {
                    display: '支付表状态', name: 'prdStsCdNm', minWidth: 50
                },
                {display: '核销状态', name: 'vfStsCdNm', minWidth: 50},
                {display: '逾期天数', name: 'ovdDay', minWidth: 60},
                {
                    display: '逾期金额(元)', name: 'ovdAmt', minWidth: 90,
                    render: function (rowdata, rowindex, value) {
                        return FormatMoney(rowdata.ovdAmt / 100);
                    }
                },
                {
                    display: '逾期租金(元)', name: 'ovdRent', minWidth: 90,
                    render: function (rowdata, rowindex, value) {
                        return FormatMoney(rowdata.ovdRent / 100);
                    }
                },
                {
                    display: '逾期利息(元)', name: 'ovdItr', minWidth: 90,
                    render: function (rowdata, rowindex, value) {
                        return FormatMoney(rowdata.ovdItr / 100);
                    }
                },
                {
                    display: '逾期罚息(元)', name: 'ovdPntItr', minWidth: 90,
                    render: function (rowdata, rowindex, value) {
                        return FormatMoney(rowdata.ovdPntItr / 100);
                    }
                },
                {
                    display: '核销时间', name: 'crtTm', minWidth: 90, render: renderDate
                },
                {
                    display: '操作', minWidth: 120, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        var h = "";
                        h += '<a class="sq-button-hasicon" href="javascript:detailInfo(';
                        h += "'" + rowdata.id + "'";
                        h += ")\"><i class='sqBtnIco_4'></i>查看</a>";
                        <sys:funcAuth resCd="ASS_VF_UPDATE">
                            h += '<a class="sq-button-hasicon" href="javascript:modifyInfo(';
                            h += "'" + rowdata.id + "'";
                            h += ")\"><i class='sqBtnIco_4'></i>修改</a>";
                        </sys:funcAuth>
                        return h;
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: false,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            isScroll: true,
            checkbox: true,//列表是否有选择框
            rownumbers: true,//列表是否有行号
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
    }

    // 格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value && value != '') {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //清空按钮事件
    function clearBtnEvent() {
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "cstNm": "",
                "cntNo": "",
                "paySchNo": ""
            });
        });
    }

    //查询按钮事件
    function searchBtnEvent() {
        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            ;
            grid.reload();
        });
    }

    // 查看核销详情
    function detailInfo(id) {
        //回调刷新列表
        var param = '<%=path%>/ass/assvfinfo/toDetailPage.do?id=' + id;
        Add_navTab('detail' + id, '查看', param, function () {
        });
    }

    // 查看修改页面
    function modifyInfo(id) {
        //回调刷新列表
        var param = '<%=path%>/ass/assvfinfo/toModifyPage.do?id=' + id;
        Add_navTab('modify' + id, '修改', param, function () {
        });
    }

    // 读取文件中的支付表后核销
    function uploadAndVf() {
        var wait_dialog = $.ligerDialog.SQalert({content: '上传中,请稍等...', SQ_type: "waitting"});
        $.ajaxFileUpload({
            url: "<%=path%>/ass/assvfinfo/importVFInfo.do",
            dataType: 'json',
            data: {},
            secureuri: false,
            fileElementId: 'upfile',
            success: function (msg) { //服务器成功响应处理函数
                wait_dialog.close();
                if (msg.success == 1) {
                    if (msg.data == "") {
                        UIUtils.alertErrorHold1("上传的EXCEL支付表编号为空");
                    } else {
                        var upfile = document.getElementById('upfile');
                        upfile.value = '';
                        grid.reload();
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    }
                } else {
                    UIUtils.alertErrorHold1(msg.info);
                }
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                wait_dialog.close();
                $.ligerDialog.SQalert({content: "网络错误，请稍后重试", SQ_type: "error"});
            }
        });
    }
</script>
</body>
</html>
